<template>
	<div>
		<div>
			<el-input
				style="width: 300px; margin-right: 10px; margin-left: -500px;"
				clearable
				@clear="initData"
				v-model="nursingLevel"
				@keydown.enter.native="initData"
			    placeholder="请输入级别进行搜索"
			    prefix-icon="el-icon-search">
			</el-input>
			<el-button type="primary" @click="initData">搜索</el-button>
			<el-button type="primary" @click="showLevelAdd">添加</el-button>
		</div>
		<div>
			<el-table
			    :data="LevelData"
			    stripe
				border
			    style="width: 100%">
			    <el-table-column
			      prop="nursingId"
			      label="序号"
			      width="100"
				  >
			    </el-table-column>
				<el-table-column
				  prop="nursingLevel"
				  label="护理级别"
				  width="150"
				  >
				</el-table-column>
			   
			    <el-table-column
			      prop="levelStatus"
			      label="状态"
				  width="150"
				  >
			    </el-table-column>
				<el-table-column
				  label="操作"
				  align="center"
				  width="200">
				  <template slot-scope="scope">
					  <el-button @click="showLevelEdit(scope.row)">编辑</el-button>
					  <el-button @click="deleteLevel(scope.row)" type="danger">删除</el-button>
				  </template>
				</el-table-column>
			  </el-table>
			  <el-pagination
			    background
				@current-change="currentChange"
			    layout="prev, pager, next,jumper,->,total"
			    :total=total>
			  </el-pagination>
		</div>
		
		<el-dialog title="级别添加" :visible.sync="dialogVisible">
		 	<LevelAdd  :dialogVisible.sync=dialogVisible @add="initData()"></LevelAdd>
		 </el-dialog>
		
		<el-dialog title="级别编辑" :visible.sync="editVisible">
			<LevelEdit :editVisible.sync="editVisible" :formData="formData"></LevelEdit>
		</el-dialog>
		
	</div> 
</template>

<script>
		import LevelAdd from './level_add.vue'
		import LevelEdit from './level_edit.vue'
	
	export default{
		name:"Nursinglevel",
		components:{
			LevelAdd,
			LevelEdit
		},
		
		data(){
			return{
				LevelData:[],
				total:0,
				currentPage:1,
				size:10,
				nursingLevel:'',
				dialogVisible:false,
				editVisible:false,
				formData:{
					nursingId:'',
					nursingLevel:'',
					levelStatus:''
					
				}
			}
		},
		mounted(){
			this.initData();
		},
		methods:{
			
			currentChange(currentPage){
				this.currentPage=currentPage;
				this.initData();
			},
			deleteLevel(data){
				this.$confirm('此操作将永久删除'+data.nursingId+'这个级别，是否继续？','提示',{
					confirmButtonText:'确定',
					cancelButtonText:'取消',
					type:'warning'
				}).then(() => {
					this.getRequest('/nursinglevel/delete?nursingId='+data.nursingId).then(resp =>{
						if(resp){
							this.initData();
						}
					})
				}).catch(() => {
					this.$message({
						type:'info',
						message:'已取消删除'
					});
				});
			},
			
			showLevelAdd(){
				this.dialogVisible=true;
			},
			
			showLevelEdit(data){
				this.editVisible=true;
				this.formData=data;
				
			},
			
			initData(){
				this.getRequest('/nursinglevel/levelList?currentPage='+this.currentPage+'&size='+this.size+'&nursingLevel='+this.nursingLevel).then(resp=>{
					if(resp){
						this.LevelData=resp.data;
						this.total=resp.total;
					}
				})
			}
		}
	}
	
</script>

<style>
</style>
